home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / sozobon / vfork.s < prev   
Text File  |  1992-01-12  |  1KB  |  50 lines

  1. ; From the mintlib.
  2. ;
  3. ; vfork for MiNT. Note that the return address must be popped off the stack,
  4. ; or else it could be clobbered by the child and the parent would be left
  5. ; returning to la-la land. Also note that MiNT guarantees that register a1
  6. ; will be preserved across a vfork() system call.
  7. ;
  8.     .globl    _vfork
  9.     .globl    ___mint        ; MiNT version kept here
  10.     .comm    L_vfsav,128
  11.     .text
  12.     .even
  13. _vfork:
  14.     move.l    (sp)+,a1    ; save return address; this is important!
  15.     tst.w    ___mint
  16.     beq    L_TOS        ; go do the TOS thing
  17.     move.w    #$113,-(sp)    ; push MiNT Pvfork() parameter
  18.     trap    #1        ; Vfork
  19.     addq.l    #2,sp
  20.     tst.l    d0        ; error??
  21.     bmi    L_err
  22.     jmp    (a1)        ; return
  23. L_TOS:
  24.     movem.l    d2-d7/a1-a6,L_vfsav    ; save registers
  25.     pea    L_vfsav
  26.     pea    L_newprog
  27.     jsr    _tfork        ; tfork(L_newprog, L_vfsav)
  28.     lea    8(sp),sp
  29.     movem.l    L_vfsav,d2-d7/a1-a6    ; restore reggies
  30.     tst.l    d0        ; fork went OK??
  31.     bmi    L_err        ; no -- error
  32.     jmp    (a1)        ; return to caller
  33. L_err:
  34.     neg.l    d0
  35.     move.w    d0,_errno    ; save error code in errno
  36.     moveq.l    #-1,d0        ; return -1
  37.     jmp    (a1)        ; return
  38.  
  39. ;
  40. ; L_newprog: here is where the child starts executing, with argument
  41. ; L_vfsav. We restore registers, zero d0, and jump back to parent
  42. ;
  43.  
  44. L_newprog:
  45.     addq.l    #4,sp        ; pop useless return address
  46.     move.l    (sp)+,a0    ; get address of save area
  47.     movem.l    (a0),d2-d7/a1-a6    ; restore reggies
  48.     clr.l    d0        ; child always returns 0 from vfork
  49.     jmp    (a1)        ; back to caller, as child process
  50.